package com.itheima.method;

public class Test7 {
    public static void main(String[] args) {
        //定义一个数组
        int[] arr = {11, 22, 33, 44, 55};
        int max = array(arr);//调用方法
        System.out.println("数组中最大值为: " + max);
    }

    public static int array(int[] arr) {
        System.out.print("[");
        //遍历数组
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                System.out.println(arr[i] + "]");//在最后一个元素后加]
            } else {
                System.out.print(arr[i] + ",");//遍历数组,输出元素,不换行打印
            }
        }
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        return max;


    }
}
